package com.zdlog.ler.util;

import com.zdlog.ler.entity.LerUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

/**
 * @program: ler-fast
 * @description:
 * @author: tengxianchao
 * @email: admin@zdlog.com
 * @create: 2018-11-24 18:54
 **/
public class EmailUtil {
    public static boolean sendEmail(JavaMailSender jms,LerUser lerUser,int code) {

        try {
            //建立邮件消息
            SimpleMailMessage mainMessage = new SimpleMailMessage();
            //发送者
            mainMessage.setFrom("注册邮件<register@zdlog.com>");
            //接收者
            mainMessage.setTo(lerUser.getEMail());
            //发送的标题
            mainMessage.setSubject("注册验证码");
            //发送的内容
            mainMessage.setText("亲爱的"+lerUser.getName()+",您本次注册的验证码为"+code);
            jms.send(mainMessage);
        } catch (Exception e) {
            return false;
        }

        return true;
    }


    public static   int makeAuthCode(){
        int authCodeNew = 0;
        authCodeNew = (int) Math.round(Math.random()*(9999-1000)+1000);
        return authCodeNew;
    }

}
